package com.bwie.assist.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.assist.entity.AddrEntity;
import com.bwie.assist.service.AddrService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 
 *
 * @author lfw
 * @email sunlightcs@gmail.com
 * @date 2022-03-25 18:53:28
 */
@RestController
@RequestMapping("assist/addr")
public class AddrController {
    @Autowired
    private AddrService addrService;

    /**
     * 查询指定地区 查询范围
     */
    @RequestMapping("/findAddrById")
    public R findAddrById(@RequestParam(value = "fid")String fid){
        List<AddrEntity> addrList = addrService.list(new QueryWrapper<AddrEntity>().eq("addr_parentid", fid));
        return R.ok().setData(addrList);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = addrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{addrId}")
    public R info(@PathVariable("addrId") Integer addrId){
		AddrEntity addr = addrService.getById(addrId);

        return R.ok().setData(addr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AddrEntity addr){
		addrService.save(addr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AddrEntity addr){
		addrService.updateById(addr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] addrIds){
		addrService.removeByIds(Arrays.asList(addrIds));

        return R.ok();
    }

}
